package com.naiterui.ehp.bs.esign.api.wukong.config;

import com.naiterui.ehp.bp.constants.EsignServiceProviderEnum;
import com.naiterui.ehp.bs.esign.api.ISignService;
import com.naiterui.ehp.bs.esign.api.wukong.exception.DefineException;
import com.naiterui.ehp.bs.esign.api.wukong.helper.ClientHelper;
import com.naiterui.ehp.bs.esign.api.wukong.service.impl.SignServiceImpl;
import com.timevale.esign.sdk.tech.v3.client.ServiceClient;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;

/**
 * @Description e签宝配置
 * @Author gongbaoqiang
 * @Date 2019/12/20 4:38 PM
 */
@Slf4j
@Data
public class ESignAutoConfiguration {

    /**
     * 注册并获取客户端
     * @return
     */
    @Bean
    public ServiceClient serviceClient() throws DefineException {
        log.info("加载签名厂商 {}", EsignServiceProviderEnum.ESIGN_WUKONG_SDK.getProviderName());
        //注册客户端
        ClientHelper.registClient();
        log.info("e签宝注册成功");
        //获取客户端
        return ClientHelper.getServiceClient(ESignProperties.PROJECT_ID);
    }

    @Bean
    public ISignService signService(ServiceClient serviceClient){

        return new SignServiceImpl(serviceClient);
    }

}
